From: Kunal Mehta Date: Wed, 20 Aug 2014 07:35:35 +0000 (-0700) Subject: Add more tests for GlobalVarConfig X-Git-Tag: 1.31.0-rc.0~14304^2 X-Git-Url: http://git.cyclocoop.org/%28%5B%5E/404?a=commitdiff_plain;h=bf89df893a0dfecd347377852b75e5724d80776c;p=lhc%2Fweb%2Fwiklou.git Add more tests for GlobalVarConfig Change-Id: I31d50a0636792104e32e3f25694f45942c5c0217 --- diff --git a/tests/phpunit/includes/config/GlobalVarConfigTest.php b/tests/phpunit/includes/config/GlobalVarConfigTest.php index 7080b02335..662f268615 100644 --- a/tests/phpunit/includes/config/GlobalVarConfigTest.php +++ b/tests/phpunit/includes/config/GlobalVarConfigTest.php @@ -2,6 +2,14 @@ class GlobalVarConfigTest extends MediaWikiTestCase { + /** + * @covers GlobalVarConfig::newInstance + */ + public function testNewInstance() { + $config = GlobalVarConfig::newInstance(); + $this->assertInstanceOf( 'GlobalVarConfig', $config ); + } + public function provideGet() { $set = array( 'wgSomething' => 'default1', @@ -28,9 +36,36 @@ class GlobalVarConfigTest extends MediaWikiTestCase { * @param string $expected * @dataProvider provideGet * @covers GlobalVarConfig::get + * @covers GlobalVarConfig::getWithPrefix */ public function testGet( $name, $prefix, $expected ) { $config = new GlobalVarConfig( $prefix ); $this->assertEquals( $config->get( $name ), $expected ); } + + public static function provideSet() { + return array( + array( 'Foo', 'wg', 'wgFoo' ), + array( 'SomethingRandom', 'wg', 'wgSomethingRandom' ), + array( 'FromAnExtension', 'eg', 'egFromAnExtension' ), + array( 'NoPrefixHere', '', 'NoPrefixHere' ), + ); + } + + /** + * @dataProvider provideSet + * @covers GlobalVarConfig::set + * @covers GlobalVarConfig::setWithPrefix + */ + public function testSet( $name, $prefix, $var ) { + if ( array_key_exists( $var, $GLOBALS ) ) { + // Will be reset after this test is over + $this->stashMwGlobals( $var ); + } + $config = new GlobalVarConfig( $prefix ); + $random = wfRandomString(); + $config->set( $name, $random ); + $this->assertArrayHasKey( $var, $GLOBALS ); + $this->assertEquals( $random, $GLOBALS[$var] ); + } }